package com.zhengshang.web.controller.app;

import java.util.List;

import com.zhengshang.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zhengshang.common.annotation.Log;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.common.enums.BusinessType;
import com.zhengshang.api.domain.AppActivity;
import com.zhengshang.api.service.IAppActivityService;
import com.zhengshang.common.utils.poi.ExcelUtil;
import com.zhengshang.common.core.page.TableDataInfo;

/**
 * APP活动Controller
 * 
 * @author zhengshang
 * @date 2021-04-05
 */
@RestController
@RequestMapping("/app/activity")
public class AppActivityController extends BaseController
{
    @Autowired
    private IAppActivityService appActivityService;

    /**
     * 查询APP活动列表
     */
    @PreAuthorize("@ss.hasPermi('app:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppActivity appActivity)
    {
        startPage();
        List<AppActivity> list = appActivityService.selectAppActivityList(appActivity);
        return getDataTable(list);
    }

    /**
     * 导出APP活动列表
     */
    @PreAuthorize("@ss.hasPermi('app:activity:export')")
    @Log(title = "APP活动", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppActivity appActivity)
    {
        List<AppActivity> list = appActivityService.selectAppActivityList(appActivity);
        ExcelUtil<AppActivity> util = new ExcelUtil<AppActivity>(AppActivity.class);
        return util.exportExcel(list, "activity");
    }

    /**
     * 获取APP活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:activity:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId)
    {
        return AjaxResult.success(appActivityService.selectAppActivityById(activityId));
    }

    /**
     * 新增APP活动
     */
    @PreAuthorize("@ss.hasPermi('app:activity:add')")
    @Log(title = "APP活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppActivity appActivity)
    {
        appActivity.setCreateBy(SecurityUtils.getUsername());
        appActivity.setStatus("1");
        return toAjax(appActivityService.insertAppActivity(appActivity));
    }

    /**
     * 修改APP活动
     */
    @PreAuthorize("@ss.hasPermi('app:activity:edit')")
    @Log(title = "APP活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppActivity appActivity)
    {
        return toAjax(appActivityService.updateAppActivity(appActivity));
    }

    /**
     * 修改APP活动
     */
    @PreAuthorize("@ss.hasPermi('app:activity:edit')")
    @Log(title = "APP活动", businessType = BusinessType.UPDATE)
    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody AppActivity appActivity)
    {
        appActivity.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(appActivityService.updateState(appActivity));
    }

    /**
     * 删除APP活动
     */
    @PreAuthorize("@ss.hasPermi('app:activity:remove')")
    @Log(title = "APP活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds)
    {
        return toAjax(appActivityService.deleteAppActivityByIds(activityIds));
    }
}
